package text;

import javax.swing.*;
import java.awt.*;

public class Ball {
    public int x;
    public int y;

    public int r;//半径
    public int type;
    public  int ori;
    public Image img_fire=new ImageIcon("1.gif").getImage();
    public Image img_foe=new ImageIcon("2.gif").getImage();
    public static final int FIRE=0;
    public static final int FOE=1;
    public  static final int UP=0;
    public  static final int DOWN=1;

    public void  draw(Graphics g){
        switch (type){
            case FIRE:
                g.drawImage(img_fire,x,y,r*2,r*2,null);
                break;
            case FOE:
                g.drawImage(img_foe,x,y,r*2,r*2,null);
                break;

        }
    }
    public void move(){
        switch (ori){
            case UP:y=y-5;break;
            case DOWN:y=y+5;break;
        }
    }
    public  boolean isTouch(Ball ball){
        int x1=x+r;
        int y1=y+r;

        int x2=ball.x+ball.r;
        int y2=ball.y+ball.r;

        double s=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        double sr=r+ball.r;
        if(s<=sr){
            return  true;
        }
        return false;
    }
}
